package cn.ztr.familyalbum.web.controller;

import cn.ztr.familyalbum.common.CommonResult;
import cn.ztr.familyalbum.common.ResultCode;
import cn.ztr.familyalbum.common.TableDataInfo;
import cn.ztr.familyalbum.dto.GrowthAlbumTemplateDto;
import cn.ztr.familyalbum.service.IGrowthAlbumTemplateService;
import cn.ztr.familyalbum.entity.GrowthAlbumTemplate;
import cn.ztr.familyalbum.vo.TemplateDictionaryVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 模板前端控制器
 */
@RestController
@RequestMapping("/growthAlbumTemplate")
@Api(value = "模板页面",tags = "模板操作接口")
public class GrowthAlbumTemplateController {
    @Autowired
    public IGrowthAlbumTemplateService growthAlbumTemplateService;


    /**
    * 删除对象信息
    *
    * @return
    */
    @RequestMapping(value="/delete",method=RequestMethod.POST)
    public CommonResult delete(@RequestBody GrowthAlbumTemplate growthAlbumTemplate){
        boolean b =  growthAlbumTemplateService.updateById(growthAlbumTemplate);
        if(b){
            return new CommonResult(ResultCode.SUCCESS);
        }
        return new CommonResult(ResultCode.INTERNAL_SERVER_ERROR);
    }

    //获取用户
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public GrowthAlbumTemplate get(@PathVariable("id")Long id)
    {
        return growthAlbumTemplateService.selectById(id);
    }



    /**
    * 分页查询数据
    *
    * @param template 查询对象
    * @return PageList 分页对象
    */
    @RequestMapping(value = "/queryTemplateList",method = RequestMethod.POST)
    public CommonResult queryTemplateList(@RequestBody GrowthAlbumTemplateDto template) {
        List templateDictionaryVoList =  growthAlbumTemplateService.queryTemplateList(template);
        TableDataInfo tableDataInfo = new TableDataInfo();
        TableDataInfo dataPage = tableDataInfo.getDataPage(templateDictionaryVoList);
        return new CommonResult(ResultCode.SUCCESS,dataPage);
    }

    /**
     * 点审核获取数据
     * @param id
     * @return
     */
    @RequestMapping(value = "/auditTemplate",method = RequestMethod.GET)
    public TemplateDictionaryVo auditTemplate(Integer id){
        return growthAlbumTemplateService.auditTemplate(id);
    }

    /**
     * 审核确定
     * @param id
     * @param state
     * @return
     */
    @RequestMapping(value = "/completeAudit",method = RequestMethod.GET)
    public CommonResult completeAudit(Integer id,Integer state){
         int num =   growthAlbumTemplateService.completeAudit(id,state);
         if(num != 0){
             return  new CommonResult(ResultCode.SUCCESS);
         }
        return new CommonResult(ResultCode.INTERNAL_SERVER_ERROR);
    }

    /**
     * 模板的新增
     * @param growthAlbumTemplate
     * @return
     */
    @RequestMapping(value = "/addTemplate",method = RequestMethod.POST)
    public CommonResult addTemplate(@RequestBody GrowthAlbumTemplate growthAlbumTemplate){
         growthAlbumTemplate.setIsDel("0");
         boolean b =   growthAlbumTemplateService.insert(growthAlbumTemplate);
         if(b){
             return  new CommonResult(ResultCode.SUCCESS);
         }
        return new CommonResult(ResultCode.INTERNAL_SERVER_ERROR);
    }
}
